﻿/********************************************************************************************************************
* Author:	Christos Polydorou																						*
* Email:	std04237@di.uoa.gr																						*
* Purpose:	This script is used in order to create the stored procedure "usp_category_setcategory" that returns a	*
*			category.																								*
********************************************************************************************************************/

CREATE PROCEDURE [dbo].[usp_category_setcategory]
	@owner nvarchar(50),
	@categoryname nvarchar(50),
	@isprivate int
AS
	DECLARE @ownerid bigint
	DECLARE @categoryid bigint

	SELECT @ownerid = id								/* Get the id of the owner */
	FROM Users
	WHERE Users.Username = @owner

	SELECT @categoryid = ID								/* Get the id of the category */
	FROM Categories
	WHERE Categories.Name = @categoryname and Categories.Owner = @ownerid

	UPDATE Categories
	SET Categories.IsPrivate = @isprivate
	WHERE Categories.Name = @categoryname and Categories.Owner = @ownerid

RETURN 0